<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
class Login extends Controller
{
    public function index()
    {
        return $this->fetch();
    }
    public function login(){
    	if (request()->isPost()) {
    		//dump(request()->post());
    		 $snumber=request()->post('snumber');
    		 $pass=md5(request()->post('pass'));
    		$re=db('students')->where('snumber',$snumber)->where('pass',$pass)->find();
            //dump($where);
    		if ($re) {
    			session('username',$re['truename']);
				session('sid',$re['sid']);
                session('cid',$re['cid']);
                session('class',$re['class']);
                session('grade',$re['grade']);
				$res=1;
    		} else {
    			$res=0;
    		}
    		return $res;
    	}	
    }
//登出处理
	public function out_login(){
		$_SESSION=array();
		//判断是否保存了cookie
			if(isset($_COOKIE[session_name()])){
				setcookie(session_name(),'',time()-1,'/');
			}		
		session('[destroy]'); //这是一个删除的函数
		//$this->redirect('index');
		$this->success('欢迎您再来！',url('login/index'),2);
	}	




}